#include "stdafx.h"
#include "PacketTest.h"
#include <string.h>

using namespace std;

// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( PacketTest );

void PacketTest::setUp() {
}
void PacketTest::tearDown() {}

void PacketTest::testSerializePacket(){
	char buffer[100];
	char buffera[100];
	char bufferb[100];
	char bufferc[100];
	char *prova = "prova";
	int size=0;
	//alloco il buffer
	GroupList l;
	u_int a = 0;
	l.push_back(2);
	Packet *p= new Packet(HELLO,1,a,l);
	size=p->serialize(buffer,100);
	cout << "size" <<size <<endl;
	Packet *p2 = Packet::read(buffer,size);
	CPPUNIT_ASSERT_EQUAL(p->getCommand(), p2->getCommand());
}
void PacketTest::testReadPFile(){
	char buffer[100];
	char bufferb[100];
	char bufferc[100];
	char *prova = "prova";
	int size=0;
	string s="cacca";
	//alloco il buffer
	GroupList l;
	u_int a = 0;
	l.push_back(2);
	
	cout << "INIZIO TEST 3"<<endl;
	PFile *pf=new PFile(START,1,a,l);
	pf->setApplicationId(2);
	pf->setApplicationName(s,s.size());
	pf->setFileOperationId(4);
	pf->setLen(5);
	size= pf->serialize(buffer,100);
	cout << "fatto serialize file " << size <<endl;
	Packet *p2 = Packet::read(buffer,size);
	CPPUNIT_ASSERT_EQUAL(pf->getCommand(), p2->getCommand());
}
	/*
	p->read(buffer,100);

	cout << "FINE TEST 1"	<<endl;
	////////////////////////
	cout << "INIZIO TEST 2" <<endl;
	PApplication *pa= new PApplication(STOP,1,a,l);
	cout << "fatto PApplication" << endl;
	pa->setApplicationId(2);
	pa->setApplicationName("cacca");
	pa->serialize(buffera,100);
	cout << "fatto serialize app" <<endl;
	p=p->read(buffera,100);
	cout << "FINE TEST 2"<<endl;
	////////////////////////////
	cout << "INIZIO TEST 3"<<endl;
	PFile *pf=new PFile(START,1,a,l);
	pf->setApplicationId(2);
	pf->setApplicationName("cacca");
	pf->setFileOperationId(4);
	pf->setLen(5);
	pf->serialize(bufferb,100);
	cout << "fatto serialize file" <<endl;
	p=p->read(bufferb,100);
	cout << "FINE TEST 3"<< endl;
	///////////////////////////////
	cout << "INIZIO TEST 4"<< endl;
	PFileTransfer *pt=new PFileTransfer(PFILE,4,a,l);
	pt->setApplicationId(6);
	pt->setOffset(7);
	pt->setBuffer(buffer,100);
	pt->serialize(bufferc,100);
	cout << "fatto serialize transfer" <<endl;
	p=p->read(bufferc,100);
	cout <<"FINE TEST 5"<< endl;
	CPPUNIT_ASSERT( 1,1);*/

	//system("pause");
	//cout << "refs = " << server.impl->getRefs() << endl;
